import tkinter as tk
from tkinter import messagebox

class application(tk.Frame):
    def __init__(self,master=None):
        super(application, self).__init__()
        self.master=master
        self.creatAPP()

    def creatAPP(self):
        self.dic={
            'font':('arial',12),
            'bg':"pink",
            'fg':'white',
            'width':8
             }
        self.b01=tk.Button(self.master,text="添加图片",cnf=self.dic,width=10)
        self.b01.grid(row=1,column=0)
        self.b01['command']=self.addImage

        self.b02=tk.Button(self.master,text='add tag',cnf=self.dic,width=10)
        self.b02.grid(row=1,column=1)
        self.b02['command']=self.addTag



        self.b04=tk.Button(self.master,text='add Button',cnf=self.dic)
        self.b04.grid(row=1,column=2)
        self.b04['command']=self.addButton

        self.t01=tk.Text(self.master,cnf=self.dic,height=30,width=50,bg='white',fg='green')
        self.t01.grid(row=2,column=0,columnspan=4)

    def addImage(self):
        self.photo=tk.PhotoImage(file='img.png')
        self.t01.image_create(tk.END,image=self.photo)

    def addTag(self):
        self.t01.insert(1.0,"https://www.baidu.com")
        self.t01.tag_add('baidu',1.0,1.21)
        self.t01.tag_config("baidu",font=("arial",20),background='pink',foreground='red')
        self.t01.tag_bind('baidu','<Button-1>',self.pt)


    def pt(self,event):
        messagebox.showinfo('测试','content')

    def close(self,event):
        self.master.destroy()
    def addButton(self):
        b03 = tk.Button(self.master, text='close', cnf=self.dic, fg='green')
        b03.bind('<Button-1>', self.close)
        self.t01.window_create(tk.END,window=b03)

window=tk.Tk()
window.geometry("1200x400")
app=application(window)
window.mainloop()
